package com.wiloon.java8x.basic.stringx;

/**
 * Created by wiloon on 7/1/17;
 */
public class StringX {

    public static void main(String[] args) {
        StringX stringX = new StringX();
        stringX.intern0();
        stringX.intern1();
        stringX.intern2();
        stringX.intern3();
        stringX.intern4();
        stringX.intern4_0();
        stringX.intern5();
    }

    private void printMethodName() {
        System.out.println();
        System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());

    }

    public void test() {
        printMethodName();
        String s = new String("1");
        s.intern();
        String s2 = "1";
        System.out.println(s == s2);

        String s3 = new String("1") + new String("1");
        s3.intern();
        String s4 = "11";
        System.out.println(s3 == s4);
    }

    public void intern0() {
        printMethodName();
        String s0 = new String("a");
        String s1 = "a";

        System.out.println(s0 == s1);
    }

    public void intern1() {
        printMethodName();
        String s0 = new String("a");
        s0 = s0.intern();
        String s1 = "a";

        System.out.println(s0 == s1);
    }

    public void intern2() {
        printMethodName();
        String s0 = new String("a");
        String s1 = "a";
        s0 = s0.intern();

        System.out.println(s0 == s1);
    }

    public void intern3() {
        printMethodName();
        String s0 = new String("a") + new String("b");
        String s1 = "ab";
        System.out.println(s0 == s1);
    }

    public void intern4() {
        printMethodName();
        String s0 = new String("a") + new String("b");
        s0.intern();
        String s1 = "ab";
        System.out.println(s0 == s1);
    }

    public void intern4_0() {
        printMethodName();
        String s0 = new String("1") + new String("2");
        s0.intern();
        String s1 = "12";
        System.out.println(s0 == s1);
    }


    public void intern5() {
        printMethodName();
        String s = new String("1");
        s.intern();
        String s2 = "1";
        System.out.println(s == s2);

        String s3 = new String("1") + new String("1");
        s3.intern();
        String s4 = "11";
        System.out.println(s3 == s4);
    }

}
